﻿using System.Text.Json.Serialization;

namespace Vin.Extension.Framework.Map.Tencent.Response;

public class WxGeocoderResponse : BaseTencentMapResponse<WxGeocoderResponse.WxGeocoderData>
{
    public class WxGeocoderData
    {
        /// <summary>
        /// 以行政区划+道路+门牌号等信息组成的标准格式化地址
        /// </summary>
        public string? Address { get; set; }

        /// <summary>
        /// 结合知名地点形成的描述性地址，更具人性化特点
        /// </summary>
        public FormattedAddressesData? FormattedAddresses { get; set; }

        /// <summary>
        /// 地址部件，address不满足需求时可自行拼接
        /// </summary>
        public AddressComponentData? AddressComponent { get; set; }

        /// <summary>
        /// 行政区划信息
        /// </summary>
        public AdInfoData? AdInfo { get; set; }
        
        /// <summary>
        /// 坐标相对位置参考
        /// </summary>
        public AddressReferenceData? AddressReference { get; set; }
        
        /// <summary>
        /// 查询的周边poi的总数，仅在传入参数get_poi=1时返回
        /// </summary>
        public int? PoiCount { get; set; }
        
        /// <summary>
        /// 周边地点（POI/AOI）列表，数组中每个子项为一个POI/AOI对象.
        /// 说明：POI即地点，如一个便利店，往往因其面积较小，其位置一般仅会标为为一个点，而学校、小区等往往面积较大，通常会有一定的地理范围，即所谓AOI，如果所请求的经纬度在AOI内，其距离会为0，且方位描述为“内”，如果是一个面积较小的地点，或不在AOI内，距离会>0，方位描述会为具体方位词，如“东”
        /// </summary>
        public List<FamousArea>? Pois { get; set; }


        public class FamousArea
        {
            /// <summary>
            /// 地点唯一标识，乡镇/街道唯一标识（行政区划代码adcode）
            /// </summary>
            public string? Id { get; set; }

            /// <summary>
            /// 名称/标题
            /// </summary>
            public string? Title { get; set; }
            
            /// <summary>
            /// 地址
            /// </summary>
            public string? Address { get; set; }
            
            /// <summary>
            /// 地点分类信息
            /// </summary>
            public string? Category { get; set; }

            /// <summary>
            /// 坐标
            /// </summary>
            public LocationData? Location { get; set; }
            
            /// <summary>
            /// 行政区划信息
            /// </summary>
            public AdInfoData? AdInfo { get; set; }

            /// <summary>
            /// 此参考位置到输入坐标的直线距离
            /// </summary>
            [JsonPropertyName("_distance")]
            public decimal? Distance { get; set; }

            /// <summary>
            /// 此参考位置到输入坐标的方位关系，如：北、南、内
            /// </summary>
            [JsonPropertyName("_dir_desc")]
            public string? DirDesc { get; set; }
        }

        public class AddressReferenceData
        {
            /// <summary>
            /// 知名区域，如商圈或人们普遍认为有较高知名度的区域
            /// </summary>
            public FamousArea? FamousArea { get; set; }

            /// <summary>
            /// 商圈
            /// </summary>
            public FamousArea? BusinessArea { get; set; }

            /// <summary>
            /// 乡镇/街道（四级行政区划）
            /// </summary>
            public FamousArea? Town { get; set; }

            /// <summary>
            /// 一级地标，可识别性较强、规模较大的地点、小区等
            /// </summary>
            public FamousArea? LandmarkL1 { get; set; }

            /// <summary>
            /// 二级地标，较一级地标更为精确，规模更小
            /// </summary>
            public FamousArea? LandmarkL2 { get; set; }

            /// <summary>
            /// 道路
            /// </summary>
            public FamousArea? Street { get; set; }

            /// <summary>
            /// 门牌
            /// </summary>
            public FamousArea? StreetNumber { get; set; }

            /// <summary>
            /// 交叉路口 
            /// </summary>
            public FamousArea? Crossroad { get; set; }

            /// <summary>
            /// 水系
            /// </summary>
            public FamousArea? Water { get; set; }

            /// <summary>
            /// 海洋信息
            /// </summary>
            public FamousArea? Ocean { get; set; }
        }

        public class LocationData
        {
            /// <summary>
            /// 纬度
            /// </summary>
            public decimal Lat { get; set; }

            /// <summary>
            /// 经度
            /// </summary>
            public decimal Lng { get; set; }
        }

        public class AdInfoData : AddressComponentData
        {
            /// <summary>
            /// 国家代码（ISO3166标准3位数字码）
            /// </summary>
            public string? NationCode { get; set; }

            /// <summary>
            /// 行政区划代码，规则详见：行政区划代码说明(https://lbs.qq.com/service/webService/webServiceGuide/search/webServiceDistrict#6)
            /// </summary>
            public string? Adcode { get; set; }

            /// <summary>
            /// 城市电话区号
            /// </summary>
            public string? PhoneAreaCode { get; set; }

            /// <summary>
            /// 城市代码，由国家码+行政区划代码（提出城市级别）组合而来，总共为9位
            /// </summary>
            public string? CityCode { get; set; }

            /// <summary>
            /// 行政区划名称
            /// </summary>
            public string? Name { get; set; }

            /// <summary>
            /// 行政区划中心点坐标
            /// </summary>
            public LocationData? Location { get; set; }
        }

        public class AddressComponentData
        {
            /// <summary>
            /// 国家
            /// </summary>
            public string? Nation { get; set; }

            /// <summary>
            /// 省
            /// </summary>
            public string? Province { get; set; }

            /// <summary>
            /// 市，如果当前城市为省直辖县级区划，city与district字段均会返回此城市  注：省直辖县级区划adcode第3和第4位分别为9、0，如济源市adcode为419001
            /// </summary>
            public string? City { get; set; }

            /// <summary>
            /// 区，可能为空字串
            /// </summary>
            public string? District { get; set; }

            /// <summary>
            /// 道路，可能为空字串
            /// </summary>
            public string? Street { get; set; }

            /// <summary>
            /// 门牌，可能为空字串
            /// </summary>
            public string? StreetNumber { get; set; }
        }

        public class FormattedAddressesData
        {
            /// <summary>
            /// 推荐使用的地址描述，描述精确性较高
            /// </summary>
            public string? Recommend { get; set; }

            /// <summary>
            /// 粗略位置描述
            /// </summary>
            public string? Rough { get; set; }
            
            /// <summary>
            /// 标准地址
            /// </summary>
            public string? StandardAddress { get; set; }
        }
    }
}